from .celery import app

from home.models import Banner
from django.conf import settings
from django.core.cache import cache
from home.serializers import BannerModelSerializer


@app.task
def update_banner_cache():
    banner_query = Banner.objects.filter(is_delete=False, is_show=True).order_by('-order')[:settings.BANNER_COUNT]
    print(banner_query)
    banner_list = BannerModelSerializer(banner_query, many=True).data
    for banner_dict in banner_list:
        banner_dict['image'] = settings.BASE_URL + banner_dict['image']
    cache.set('banner_list', banner_list)
